package com.example.framework;

import org.openqa.selenium.By;


public class NavigationHelper extends BaseHelperWithWebDriver{
	public NavigationHelper(ApplicationManager manager) {
		super(manager);
	}

	protected void openAddNewContactPage() {
		//check if this page is already open
		if (isElementPresent(By.xpath(manager.getProperties("newContactPageElement")))) {
			return;
		}	else
			click(By.linkText(manager.getProperties("addNew")));
	}

	public void openSite() {
		String url = manager.getProperties("baseUrl");
		if (!getCurrentUrl().equals(url)) {
			openUrl(url);
		}
	}

	protected void openGroupsPage() {
		String url = manager.getProperties("baseUrl");
		if (!getCurrentUrl().equals(url)) {
					openUrl(url);
				}
		//check if this page is already open
		if (isElementPresent(By.xpath(manager.getProperties("newGroupButton")))) {
			return;
		}	else
			click(By.linkText("groups"));
	}

	public void openHomePage() {
		//check if this page is already open
		if (isElementPresent(By.id(manager.getProperties("maintable")))) {
			return;
		}	else
			click(By.linkText(manager.getProperties("homePageLink")));
	}
	public void submitCreation() {
		findElement(By.name(manager.getProperties("submitCreationButton"))).click();
	}

	public void goToPrintPhonesPage() {
		manager.getSeleniumHelper();
		//check if this page is already open
		if (!manager.getSeleniumHelper().getSelenium().getCurrentUrl().equals(manager.getProperties("printPhonesUrl")))
			click(By.linkText(manager.getProperties("printPhonesPageLink")));
	}
}
